home *** CD-ROM | disk | FTP | other *** search
/ Amiga Inside! / Amiga FD Inside (1995)(Ultramax).iso / forumamiga / programme / iconify / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-31  |  5.1 KB  |  217 lines

  1. /**
  2.  **  IconifyClass testen, Holgi am 31.07.94 mit MaxonC
  3.  **  benötigt OS2.0+
  4.  **
  5.  **  Tabsize = 3
  6.  **/
  7.  
  8. #include <exec/types.h>
  9. #include <pragma/dos_lib.h>
  10. #include <pragma/exec_lib.h>
  11. #include <pragma/icon_lib.h>
  12. #include <pragma/intuition_lib.h>
  13. #include <pragma/wb_lib.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <intuition/imageclass.h>
  16. #include <workbench/startup.h>
  17.  
  18. #include "IconifyClass.h"
  19.  
  20. #define ICON_WIDTH (26)
  21. #define ICON_ID    (1000)
  22.  
  23. void     Test();
  24. BOOL     OpenWin();
  25. void     CloseWin();
  26. BOOL     AddIcon();
  27. void     RemoveIcon();
  28.  
  29. STRPTR             ProgName;
  30. struct Library *IntuitionBase;
  31. struct Library    *GfxBase;
  32. struct Library *IconBase;
  33. struct Library *WorkbenchBase;
  34. struct IClass    *IconifyClass;
  35.  
  36. struct Screen        *MyScr        = NULL;
  37. Object                *MyIcon        = NULL;
  38. Object                *MyIconGG    = NULL;
  39. struct Window        *MyWin         = NULL;
  40. struct MsgPort        *IconPort    = NULL;
  41. struct DiskObject    *ProgIcon    = NULL;
  42. struct AppIcon        *AppIcon        = NULL;
  43.  
  44. void wbmain( struct WBStartup *ws )
  45. {
  46.     CurrentDir( ws->sm_ArgList->wa_Lock );
  47.     ProgName = ws->sm_ArgList->wa_Name;
  48.     Test();
  49. }
  50.  
  51. main()
  52. {
  53.     BPTR    OldLock, ProgLock;
  54.     UBYTE NameBuf[ 32 ];
  55.  
  56.     if( ProgLock = Lock( "PROGDIR:", ACCESS_READ ))
  57.     {
  58.         OldLock = CurrentDir( ProgLock );
  59.         if( GetProgramName( NameBuf, sizeof( NameBuf )))
  60.         {
  61.             ProgName = NameBuf;
  62.             Test();
  63.         }
  64.         CurrentDir( OldLock );
  65.         UnLock( ProgLock );
  66.     }
  67. }
  68.  
  69. void Test()
  70. {
  71.     if( IntuitionBase = OpenLibrary( "intuition.library", 36 ))
  72.     {
  73.         if( GfxBase = OpenLibrary( "graphics.library", 36 ))
  74.         {
  75.             if( IconBase = OpenLibrary( "icon.library", 36 ))
  76.             {
  77.                 if( WorkbenchBase = OpenLibrary( "workbench.library", 36 ))
  78.                 {
  79.                     if( IconifyClass = InitIconify( IntuitionBase, GfxBase ))
  80.                     {
  81.                         if( OpenWin())
  82.                         {
  83.                             BOOL Finished  = FALSE,
  84.                                   Iconified = FALSE;
  85.  
  86.                             while( !Finished )
  87.                             {
  88.                                 if( Iconified )
  89.                                 {
  90.                                     WaitPort( IconPort );
  91.                                     RemoveIcon();
  92.                                     Finished  = !OpenWin();
  93.                                     Iconified = FALSE;
  94.                                 }
  95.                                 else
  96.                                 {
  97.                                     struct IntuiMessage *IMsg;
  98.                                     struct Gadget *MsgObj;
  99.                                     ULONG  MsgClass;
  100.  
  101.                                     WaitPort( MyWin->UserPort );
  102.                                     while( !Finished && (IMsg = (struct IntuiMessage *)
  103.                                                                          GetMsg( MyWin->UserPort )))
  104.                                     {
  105.                                         MsgClass = IMsg->Class;
  106.                                         MsgObj    = (struct Gadget *) IMsg->IAddress;
  107.                                         ReplyMsg( (struct Message *) IMsg );
  108.                                         
  109.                                         switch( MsgClass )
  110.                                         {
  111.                                             case IDCMP_CLOSEWINDOW:
  112.                                                 Finished = TRUE;
  113.                                                 break;
  114.  
  115.                                             case IDCMP_GADGETUP:
  116.                                                 if( MsgObj->GadgetID == ICON_ID )
  117.                                                 {
  118.                                                     CloseWin();
  119.                                                     Finished  = !AddIcon();
  120.                                                     Iconified = TRUE;
  121.                                                 }
  122.                                             default:
  123.                                                 break;
  124.                                         }
  125.                                     }
  126.                                 }
  127.                             }
  128.                         }
  129.                         RemoveIcon();
  130.                         CloseWin();
  131.                         RemoveIconify( IconifyClass );
  132.                     }
  133.                     CloseLibrary( WorkbenchBase );
  134.                 }
  135.                 CloseLibrary( IconBase );
  136.             }
  137.             CloseLibrary( GfxBase );
  138.         }
  139.         CloseLibrary( IntuitionBase );
  140.     }
  141. }
  142.  
  143. BOOL OpenWin()
  144. {
  145.     if( MyScr = LockPubScreen( NULL ))
  146.     {
  147.         struct TagItem IconTags[] = {
  148.             IA_Left,0, IA_Top,0, IA_Width,ICON_WIDTH,
  149.             IA_Height,MyScr->BarHeight + 1, TAG_DONE,0
  150.         };
  151.         if( MyIcon = NewObjectA( IconifyClass, NULL, IconTags ))
  152.         {
  153.             struct TagItem IconGGTags[] = {
  154.                 GA_RelRight,-70, GA_Top,0, GA_Width,ICON_WIDTH,
  155.                 GA_Height,MyScr->BarHeight + 1, GA_Image,(ULONG) MyIcon,
  156.                 GA_RelVerify,TRUE, GA_ID,ICON_ID, TAG_DONE,0
  157.             };
  158.             if( MyIconGG = NewObjectA( NULL, BUTTONGCLASS, IconGGTags ))
  159.             {
  160.                 struct TagItem WinTags[] = {
  161.                     WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
  162.                     WA_Title,(ULONG) "IconifyClass Test",
  163.                     WA_MinWidth,70 + 18 + ICON_WIDTH,
  164.                     WA_MinHeight,MyScr->BarHeight + 11, WA_MaxWidth,~0,
  165.                     WA_MaxHeight,~0, WA_SizeGadget,TRUE, WA_DragBar,TRUE,
  166.                     WA_DepthGadget,TRUE, WA_CloseGadget,TRUE,
  167.                     WA_NoCareRefresh,TRUE, WA_Activate,TRUE, WA_RMBTrap,TRUE,
  168.                     WA_SmartRefresh,TRUE, WA_AutoAdjust,TRUE,    WA_InnerWidth,400,
  169.                     WA_InnerHeight,100, WA_PubScreen,(ULONG) MyScr, TAG_DONE,0
  170.                 };
  171.                 if( MyWin = OpenWindowTagList( NULL, WinTags ))
  172.                 {
  173.                     AddGadget( MyWin, (struct Gadget *) MyIconGG, 0 );
  174.                     RefreshGList( (struct Gadget *) MyIconGG, MyWin, NULL, 1 );
  175.                 }
  176.             }
  177.         }
  178.     }
  179.     return( MyWin != NULL );
  180. }
  181.  
  182. void CloseWin()
  183. {
  184.     if( MyWin )        { CloseWindow( MyWin );                 MyWin     = NULL; }
  185.     if( MyIconGG )    { DisposeObject( MyIconGG );         MyIconGG = NULL; }
  186.     if( MyIcon )    { DisposeObject( MyIcon );             MyIcon     = NULL; }
  187.     if( MyScr )        { UnlockPubScreen( NULL, MyScr ); MyScr     = NULL; }
  188. }
  189.  
  190. BOOL AddIcon()
  191. {
  192.     STRPTR ProgName = "Test";
  193.     
  194.     if( IconPort = CreateMsgPort())
  195.     {
  196.         if( ProgIcon = GetDiskObjectNew( ProgName ))
  197.         {
  198.             ProgIcon->do_CurrentX = ProgIcon->do_CurrentY = NO_ICON_POSITION;
  199.             AppIcon = AddAppIconA( 0, 0, ProgName, IconPort, NULL, ProgIcon, NULL );
  200.         }
  201.     }
  202.     return( AppIcon != NULL );
  203. }
  204.  
  205. void RemoveIcon()
  206. {
  207.     if( AppIcon )    { RemoveAppIcon( AppIcon );    AppIcon    = NULL; }
  208.     if( ProgIcon )    { FreeDiskObject( ProgIcon );    ProgIcon    = NULL; }
  209.     if( IconPort )
  210.     {
  211.         struct Message *Msg;
  212.         while( Msg = GetMsg( IconPort )) ReplyMsg( Msg );
  213.         DeleteMsgPort( IconPort );
  214.         IconPort = NULL;
  215.     }
  216. }
  217.